package com.example.keli.ui.reward;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;

import com.example.keli.R;
import com.example.keli.api.RetrofitManager;
import com.example.keli.api.http.api.BaseResponse;
import com.example.keli.api.http.api.subscriber.SubscriberListener;
import com.example.keli.base.BaseFragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * description $desc$
 * created by jerry on 2019/3/18.
 */
public class RewardObjectFragment extends BaseFragment {

    private static final String TAG = "RewardObjectFragment";
    public static final String REWARD_URL = "http://keli.h5ck.com/jiangpin.html";

    @BindView(R.id.webView)
    WebView webView;
//    @BindView(R.id.recycler_reward_rank)
//    RecyclerView recyclerRewardRank;

//    private RewardRankAdapter rewardRankAdapter;
//    private RewardList.RewardVO mRewardVO;
//    private List<RewardDetailsActivity.RewardRank> ranks;

    public static RewardObjectFragment newInstance() {
        RewardObjectFragment rewardObjectFragment = new RewardObjectFragment();
        Bundle bundle = new Bundle();
//        bundle.putSerializable("reward", rewardVO);
        rewardObjectFragment.setArguments(bundle);
        return rewardObjectFragment;
    }

    @Override
    protected int layoutId() {
        return R.layout.fragment_rewardobject;
    }

    @Override
    protected void bindData() {
//        loadDatas();
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setDefaultTextEncodingName("UTF-8");
        webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
        webView.setWebChromeClient(new WebChromeClient());
        webView.loadUrl(REWARD_URL);
    }

//    private void initRewardRankRecycle() {
////        mRewardVO = (RewardList.RewardVO) getArguments().getSerializable("reward");
//        ranks = new ArrayList<>();
//        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext());
//        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
//        recyclerRewardRank.setLayoutManager(linearLayoutManager);
//        recyclerRewardRank.setNestedScrollingEnabled(false);
//        if (!TextUtils.isEmpty(mRewardVO.getReward_one_content())){
//            RewardDetailsActivity.RewardRank rank = new RewardDetailsActivity.RewardRank();
//            rank.setTitle(mRewardVO.getReward_one_title());
//            rank.setImg(mRewardVO.getReward_one_img());
//            rank.setContent(mRewardVO.getReward_one_content());
//            ranks.add(rank);
//        }
//        if (!TextUtils.isEmpty(mRewardVO.getReward_two_content())){
//            RewardDetailsActivity.RewardRank rank = new RewardDetailsActivity.RewardRank();
//            rank.setTitle(mRewardVO.getReward_two_title());
//            rank.setImg(mRewardVO.getReward_two_img());
//            rank.setContent(mRewardVO.getReward_two_content());
//            ranks.add(rank);
//        }
//        if (!TextUtils.isEmpty(mRewardVO.getReward_three_content())){
//            RewardDetailsActivity.RewardRank rank = new RewardDetailsActivity.RewardRank();
//            rank.setTitle(mRewardVO.getReward_three_title());
//            rank.setImg(mRewardVO.getReward_three_img());
//            rank.setContent(mRewardVO.getReward_three_content());
//            ranks.add(rank);
//        }
//        if (!TextUtils.isEmpty(mRewardVO.getReward_four_content())){
//            RewardDetailsActivity.RewardRank rank = new RewardDetailsActivity.RewardRank();
//            rank.setTitle(mRewardVO.getReward_four_title());
//            rank.setImg(mRewardVO.getReward_four_img());
//            rank.setContent(mRewardVO.getReward_four_content());
//            ranks.add(rank);
//        }
//        rewardRankAdapter = new RewardRankAdapter(getContext(), R.layout.item_reward_rank, ranks);
//        recyclerRewardRank.setAdapter(rewardRankAdapter);
//    }
//
//    private void loadDatas() {
//        Map<String, String> map = new HashMap<>();
//        map.put("page", String.valueOf("1"));
//        RetrofitManager.ApiFunc(RetrofitManager.mApiService.getReward(map), new SubscriberListener<BaseResponse<RewardList>>() {
//            @Override
//            public void onSuccess(BaseResponse<RewardList> rewardListBaseResponse) {
//                Log.e(TAG, "onSuccess: "+rewardListBaseResponse.data);
//                List<RewardList.RewardVO> data = rewardListBaseResponse.data.getData();
//                mRewardVO = data.get(0);
//                initRewardRankRecycle();
//            }
//
//            @Override
//            public void onFailer(String msg) {
////                mRefreshlayout.setRefreshing(false);
//            }
//
//            @Override
//            public void onTokenError() {
////                mRefreshlayout.setRefreshing(false);
//            }
//        });
//    }

    @Override
    protected void bindListener() {
    }
}
